home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Mathematics / Notebooks / URichCalculusII / 6 / Lab6.ma next >
Encoding:
Text File  |  1992-08-19  |  16.1 KB  |  261 lines

  1. (*^
  2.  
  3. ::[paletteColors = 128; currentKernel; 
  4.     fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e8,  24, "Times"; ;
  5.     fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e6,  18, "Times"; ;
  6.     fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, L1, e6,  14, "Times"; ;
  7.     fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, L1, a20,  18, "Times"; ;
  8.     fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, L1, a15,  14, "Times"; ;
  9.     fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, L1, a12,  12, "Times"; ;
  10.     fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  11.     fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  10, "Times"; ;
  12.     fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L1,  12, "Courier"; ;
  13.     fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5,  12, "Courier"; ;
  14.     fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  15.     fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  16.     fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  17.     fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L1,  12, "Courier"; ;
  18.     fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, L1,  10, "Times"; ;
  19.     fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  20.     fontset = Left Header, nohscroll, cellOutline,  12;
  21.     fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, L1,  12;
  22.     fontset = Left Footer, cellOutline, blackBox,  12;
  23.     fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  10, "Times"; ;
  24.     fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  25.     fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12, "Courier"; ;
  26.     fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  27.     fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  28.     fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  29.     fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  30.     fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  31.     next21StandardFontEncoding; ]
  32. :[font = title; inactive; Cclosed; preserveAspect; startGroup; ]
  33. Lab 6:  Sequences
  34. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  35. Simple Sequences
  36. :[font = text; inactive; preserveAspect; ]
  37. We studied sequences in Section 10.1 of Stein's textbook.  This lab uses all three of Mathematica's facilities (graphical, analytical, and numerical) to assist this study.  Pages 200-206 in the Crooke/Ratcliffe Guidebook cover this same material.
  38. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  39. Example
  40. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  41. Here's an example we did in class:
  42. :[font = input; preserveAspect; ]
  43. a[n_] := (1+1/n)^n
  44. :[font = text; inactive; preserveAspect; endGroup; ]
  45. We know that this sequence converges to the constant e.
  46. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  47. The Table command produces a subsequence of the sequence:
  48. ;[s]
  49. 3:0,0;3,1;10,2;58,-1;
  50. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  51. :[font = input; preserveAspect; ]
  52. points = Table[ a[n], {n,1,8} ]
  53. :[font = text; inactive; preserveAspect; ]
  54. and the N command  gives us their numerical (decimal) values:
  55. ;[s]
  56. 3:0,0;7,1;10,2;61,-1;
  57. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  58. :[font = input; preserveAspect; endGroup; ]
  59. N[points]
  60. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  61. The ListPlot command produces a graphical indication of the convergence:
  62. ;[s]
  63. 3:0,0;3,1;13,2;73,-1;
  64. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  65. :[font = input; preserveAspect; ]
  66. ListPlot[ points, PlotStyle -> PointSize[0.02] ];
  67. :[font = text; inactive; preserveAspect; endGroup; ]
  68. Evidently, the points are leveling off at about 2.7.
  69. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  70. Here's the Table command again.  But this time we use 2^k in place of n to get the subsequence {a[2], a[4], a[8], a[16], a[32], a[64], a[128], a[256]}.  This gets us closer to the limit faster, but it takes Mathematica a little longer to generate.
  71. ;[s]
  72. 11:0,0;10,1;17,2;53,3;58,4;69,5;72,6;94,7;150,8;207,9;218,10;247,-1;
  73. 11:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  74. :[font = input; preserveAspect; ]
  75. points = Table[ {2^k,a[2^k]}, {k,1,8} ] // N
  76. :[font = input; preserveAspect; ]
  77. TableForm[points]
  78. :[font = input; preserveAspect; endGroup; ]
  79. ListPlot[ points, PlotStyle -> PointSize[0.02] ];
  80. :[font = text; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  81. Finally, we try the Limit command to see if we can get the exact limit:
  82. ;[s]
  83. 3:0,0;19,1;26,2;72,-1;
  84. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  85. :[font = input; preserveAspect; ]
  86. Limit[ a[n], n -> Infinity ]
  87. :[font = text; inactive; preserveAspect; ]
  88. and its numerical value:
  89. :[font = input; preserveAspect; ]
  90. N[%]
  91. :[font = input; preserveAspect; ]
  92. N[%,16]
  93. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  94. Notice that Mathematics denotes the constant e by E.  This is consistent with its rule that all predefined symbols are capitalized.
  95. ;[s]
  96. 3:0,0;12,1;23,2;131,-1;
  97. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  98. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  99. Exercises
  100. :[font = text; inactive; preserveAspect; ]
  101. For the sequence defined in each of the following exercises from our textbook: 
  102.     (a)  define the function a[n_];
  103.     (b)  use the Table command to produce a list of the first 8 terms;
  104.     (c)  use the ListPlot command to plot the points produced in (b);
  105.     (d)  use the Table command with 2^k in place of n, and with the  // N 
  106.      function, to produce a table of terms indexed by the first 8 powers of 2;
  107.     (e)  use the ListPlot command to plot the points produced in (d);
  108.     (f)  use the Limit command to obtain the limit of the sequence, in both symbolic 
  109.            and numerical form.
  110. In other words, execute all the commands given in the example above.
  111. ;[s]
  112. 18:0,0;108,1;114,2;132,3;139,4;203,5;213,6;273,7;280,8;292,9;297,10;308,11;310,12;324,13;337,14;427,15;437,16;497,17;721,-1;
  113. 18:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;
  114. :[font = text; inactive; preserveAspect; ]
  115. 1.  Exercise 1 on page 494.
  116. :[font = text; inactive; preserveAspect; ]
  117. 2.  Exercise 2 on page 494.
  118. :[font = text; inactive; preserveAspect; ]
  119. 3.  Exercise 4 on page 494.
  120. :[font = text; inactive; preserveAspect; ]
  121. 4.  Exercise 15 on page 494.
  122. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  123. 5.  The sequence n^(1/n).
  124. :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  125. Recursive Sequences
  126. :[font = text; inactive; preserveAspect; ]
  127. A recursive sequence is a sequence where the terms are defined in terms of previous terms, instead of being defined by a "closed" formula (i.e. a direct function of n).
  128. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  129. Example
  130. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  131. The Fibonacci sequence (Exercise 34 on page 495) is defined recursively:
  132. :[font = input; preserveAspect; ]
  133. Clear[f];
  134. f[1] = 1;
  135. f[2] = 1;
  136. f[n_] := f[n-1] + f[n-2]
  137. :[font = text; inactive; preserveAspect; ]
  138. The recursion formula on the third line can be used by Mathematica to compute 
  139. f[n] for any n > 2.  
  140. ;[s]
  141. 7:0,0;55,1;66,2;79,3;84,4;91,5;94,6;101,-1;
  142. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  143. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  144. For example:
  145. :[font = input; preserveAspect; ]
  146. f[3]
  147. :[font = input; preserveAspect; ]
  148. f[4]
  149. :[font = input; preserveAspect; endGroup; ]
  150. f[14]
  151. :[font = text; inactive; preserveAspect; endGroup; ]
  152. Of course, to compute f[14], it had to compute its predecessors f[3] through f[13] first.
  153. ;[s]
  154. 7:0,0;21,1;27,2;63,3;69,4;76,5;83,6;89,-1;
  155. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  156. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  157. The Fibonacci sequence diverges, because it increases without bound.  But Mathematica is unable to discover that fact.  The following command will produce some error messages, but then it will continue to run.  To abort it, give the Abort Calculation command in the Action>Interrupt submenu (or press Command- .).
  158. ;[s]
  159. 9:0,0;74,1;85,2;233,3;250,4;266,5;282,6;301,7;311,8;314,-1;
  160. 9:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,9,Helvetica,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,9,Helvetica,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,9,Helvetica,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  161. :[font = input; preserveAspect; ]
  162. f[n]
  163. :[font = text; inactive; preserveAspect; ]
  164. When you abort a running execution, Mathematica remembers your definitions.  To check that it did, execute the following command which asks Mathematica for its current definition of the symbol f:
  165. ;[s]
  166. 7:0,0;36,1;47,2;140,3;151,4;192,5;194,6;195,-1;
  167. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  168. :[font = input; preserveAspect; endGroup; endGroup; ]
  169. ?f
  170. :[font = subsection; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  171. Exercises
  172. :[font = text; inactive; preserveAspect; ]
  173. For the sequence defined in each of the following exercises: 
  174.     (a)  define the recursive function a[n_];
  175.     (b)  use the Table command to produce a list of the first 8 terms;
  176.     (c)  use the ListPlot command to plot the points produced in (b);
  177.     (d)  Make a numerical estimate (to 4 decimal places) of the limit of the sequence.
  178. Use the same commands that you used in the first section.  Remember to Clear[a].
  179. ;[s]
  180. 9:0,0;100,1;106,2;124,3;131,4;195,5;205,6;406,7;415,8;417,-1;
  181. 9:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  182. :[font = text; inactive; preserveAspect; ]
  183. 1.  The sequence of Fibonacci ratios: a[n] = f [n+1] / f [n].  (See part (c) of 
  184.       exercise 34 on page 494.
  185. ;[s]
  186. 3:0,0;37,1;60,2;112,-1;
  187. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  188. :[font = text; inactive; preserveAspect; ]
  189. 2.  a[n_] := 1/(1+a[n-1]); a[1] = 1;
  190. ;[s]
  191. 5:0,0;4,1;25,2;26,3;35,4;37,-1;
  192. 5:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  193. :[font = text; inactive; preserveAspect; ]
  194. 3.  a[n_] := Sqrt[1+a[n-1]]; a[1] = 1;
  195. ;[s]
  196. 5:0,0;4,1;27,2;28,3;37,4;39,-1;
  197. 5:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  198. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  199. 4.  Exercise 35 on page 495.  (Use a[n_] := (1+a[n-1])/a[n-2], a[1] = 1,
  200.      and a[2] = 3).
  201. ;[s]
  202. 7:0,0;34,1;61,2;62,3;71,4;81,5;90,6;93,-1;
  203. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  204. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  205. Newton's Method
  206. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  207. Example
  208. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  209. Recall Newton's method (Section 6.10) for numerically solving equations of the form  
  210.                                                      f(x) = 0 
  211. If x is close to the solution, then ( x - f (x) / f'(x) ) will be closer.
  212. ;[s]
  213. 7:0,0;138,1;147,2;151,3;154,4;184,5;207,6;222,-1;
  214. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  215. :[font = text; inactive; preserveAspect; ]
  216. For example, to find a numerical approximation to the sixth root of 2, we set up the function f[x_] := x^6 - 2 , so that the number we want is the solution to the equation
  217.                                                  x^6 - 2  = 0 
  218.                                                  
  219. Then  x - f(x)/f'(x) = x - (x^6-2)/(6x^5) = (5x^6+2)/(6x^5).  So we set up a recursive sequence a[n], with a[1]=1 and each successive a[n] computed from its predecessor using the above expression for x - f(x)/f'(x).
  220. ;[s]
  221. 15:0,0;93,1;110,2;221,3;233,4;289,5;344,6;380,7;385,8;391,9;399,10;418,11;424,12;484,13;499,14;500,-1;
  222. 15:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  223. :[font = input; preserveAspect; ]
  224. Clear[f];
  225. f[x_] := x^6 - 2
  226. :[font = input; preserveAspect; ]
  227. x - f[x]/f'[x]
  228. :[font = input; preserveAspect; ]
  229. a[n_] := a[n-1] - f[a[n-1]]/f'[a[n-1]]; a[1] := 1;
  230. :[font = input; preserveAspect; endGroup; ]
  231. Table[ a[n], {n,1,5} ]  //  N
  232. :[font = text; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  233. Newton's Method converges rapidly.  We see that the fifth iterate is correct to six significant digits:
  234. :[font = input; preserveAspect; ]
  235. Solve[f[x]==0,x]  //  N
  236. :[font = input; preserveAspect; endGroup; ]
  237. N[2^(1/6)]
  238. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  239. Another way to check the answer is to substitute it back into the original equation:
  240. :[font = input; preserveAspect; ]
  241. f[a[5]]  //  N
  242. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  243. The answer here should be very close to zero.
  244. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  245. Exercises
  246. :[font = text; inactive; preserveAspect; ]
  247. Use Newton's Method to solve the following equations, and then compare your fifth iterate with the output from the Solve command.  Then check your answer by evaluating  f[a[5]]  //  N .
  248. ;[s]
  249. 5:0,0;114,1;121,2;167,3;183,4;186,-1;
  250. 5:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  251. :[font = text; inactive; preserveAspect; ]
  252. 1.  tan x = 1 - x^2   (Let f[x_] := 1 - x^2 - Tan[x]).
  253. ;[s]
  254. 3:0,0;26,1;52,2;55,-1;
  255. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  256. :[font = text; inactive; preserveAspect; endGroup; endGroup; endGroup; ]
  257. 2.  sin x = ln x   (Let f[x_] := Sin[x] - Log[x]).
  258. ;[s]
  259. 3:0,0;23,1;48,2;51,-1;
  260. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  261. ^*)